<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  h2 {font-size: 17px;color: #000000; display : inline}
  input[readonly="readonly"]{
    background: #ffffff;
    color: #ccc;
  }
</style>
<template>
  <div>
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      调价
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <!--      <form action="/sales/Sellform!saveOrUpdate .action?openid=${openid}" method="post" id="formid">-->
      <form method="post"  id="formid">

        <div class="weui-cell" v-if="orderfiles.length > 0">
          <div class="weui-cell__hd"><label class="weui-label">附件</label></div>
          <div class="weui-cell__bd">
            <a v-for="(item, index) in orderfiles" :href="item.url">
              <input class="weui-input" type="text" name="" :value="item.filename">
            </a>
            <!--              <input class="weui-input" type="text" name="" :value="baseInfo.createtime">-->
          </div>
        </div>
        <div class="oitem"  v-for="(item, index) in data" :key="item.guid">
          <div class="weui-cells__title">货品明细 <h2 >({{index + 1}})</h2>
            <input type="hidden"  :name="appand(index,'guid')" :value="item.guid" />
            <input type="hidden"  name="orderguid" :value="guid" />
            <p id="acts" style="float: right;color: #1aad19;">
              <!--<span id="addItem" style="padding-right: 5px;">添加</span>-->
            </p>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="productguid1" class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly="true" id="productguid1" :value="item.productname"  placeholder="请选择品种">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="spguid1" class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly="true" id="spguid1" :value="item.spname"  placeholder="请选择规格">
            </div>
          </div>


          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价(元/吨)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number"  id="price" :value="item.price"  :name="appand(index,'price')" placeholder="请输入单价">
            </div>
          </div>


        </div>
        <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="send">保存</a>
          <a class="weui-btn weui-btn_primary halfbtn" href="javascript:"  @click="$router.back(-1)" id="sub">取消</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'ChangePrice',
    data () {
      return {
        guid : "",
        nodeid : "",
        status : "",
        data: [],
        wxConf:{},
        postParams: {
          pageSize: "1"
        },
        loading: false,
        showLoadIcon: false,
        showNomore: false,
        wrapperHeight: 600,
        userCode: localStorage.userCode || '',//用户code
        images: {
          localId: [], //已选择的本地图片
          serverId: [] //微信服务器返回的mediaId
        },
        saveImages: {
          previewImageList: [], //预览大图数组,
          previewThumbList: [], //预览缩略图数组
          saveImageList: [], //预览大图数组//保存图片
        },
        uploadPath: '', //图片上传的路径：为空时，默认下载到当前项目的/mcupload路径下
        orderfiles: []


      }
    },
    mounted () {
      this.guid = this.$route.query.guid;
      this.nodeid = this.$route.query.nodeid;
      this.status = this.$route.query.status;
      this.axios({
        method: 'get',
        url: '/sales/Sellitem!getItem.action',
        params:  {sellguid:this.guid}
      }).then(response => {
        this.data = response.data.info;
      });
      this.getFiles();

    },
    methods: {
      getFiles: function() {
        let that = this;
        this.axios({
          method: 'get',
          url: '/sales/Fileinfo!getFileinfo.action',
          params: {orderid: this.guid}
        }).then(response => {

          if (response.data.msg == 'success') {
            this.orderfiles = response.data.files;
          } else {
            //失败时不提示
          }
        });
      },

      send: function() {
        let that = this;

        //防止重复提交
        $('.subbtn').attr("disabled",true).css("pointer-events","none");
        //显示提交状态
        $.showLoading("正在提交");

        this.axios({
          method: 'post',
          responseType: 'json',
          headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
          url: '/sales/Sellitem!chnagePrice.action?nodeid=' + this.nodeid + '&status=' + this.status,
          params: this.serialize2Obj($("#formid").serializeArray())
        }).then(response => {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();

          if(response.data.info == "ok"){
            this.toastText('操作成功!');
          }else{
            this.toastText('操作失败!');

          }
          this.$router.push({name: 'Sellform'});
        }).catch(function (error) {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();
          that.toastError('系统错误');
        });
      },
      appand:function (index,key){
        return "sellitems[" + index + "]." + key;
      }

    }

  }
</script>


